package org.hq.common.interceptor;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;
import org.hq.common.model.SystemConstants;
import org.hq.system.action.LoginAction;
import org.hq.system.model.UserVO;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

/**
 * @author eric
 * @description 登录授权拦截 
 * Sep 9, 2013 2:14:14 PM
 */
public class AuthorizationInterceptor extends AbstractInterceptor {

	@Override
	public String intercept(ActionInvocation arg0) throws Exception {
		Object action = arg0.getAction();
		if (action instanceof LoginAction) {
			return arg0.invoke();
		}
		UserVO userVO = null;
		HttpSession session = ServletActionContext.getRequest().getSession();
		if (null != session) {
			userVO = (UserVO) session
					.getAttribute(SystemConstants.SESSION_USERMESSAGE);
		}
		if (null != userVO) {
			return arg0.invoke();
		} else {
			return "loginout";
		}
	}
}
